from selenium.webdriver.common.by import By


class PageBackendMenu():
    def __init__(self, driver):
        self.driver = driver

    # 选择【订单管理】
    def ele_order_button(self):
        self.driver.find_element(By.XPATH, '//ul[@id="menu-ul"]/li[3]').click()

    # 选择【订单查询】
    def ele_order_search(self):
        self.driver.find_element(By.XPATH, '//ul[@id="menu-ul"]/li[3]/ul/li[2]/a').click()

    # 打开进入【商品管理】
    def ele_goods_manage(self):
        self.driver.find_element(By.CLASS_NAME, 'collapse').click()

     # 点击【商品列表】进入商品页面
    def ele_goods_list(self):
        self.driver.find_element(By.LINK_TEXT, '商品列表').click()

    # 点击【添加新商品】按钮
    def ele_add_goods(self):
        self.driver.find_element(By.LINK_TEXT, '添加新商品').click()

    # 点击【商品批量导出】按钮
    def ele_batch_derive(self):
        self.driver.find_element(By.LINK_TEXT, '商品批量导出').click()

    # 点击【商品批量上传】按钮
    def ele_derive_uploading(self):
        self.driver.find_element(By.LINK_TEXT, '商品批量上传').click()
    # 进入左侧menuframe
    def ele_menu_frame(self):
        self.driver.switch_to.frame('menu-frame')

    #进入右侧mainframe
    def ele_main_frame(self):
        self.driver.switch_to.frame('main-frame')

    # 退出frame
    def ele_frame_out(self):
        self.driver.switch_to.default_content()

    def search_order(self):
        self.ele_menu_frame()
        self.ele_order_button()
        self.ele_order_search()
        self.ele_frame_out()

    def goods_list(self):
        self.ele_menu_frame()
        self.ele_goods_manage()
        self.ele_goods_list()
        self.ele_frame_out()

    def add_goods(self):
        self.ele_menu_frame()
        self.ele_goods_manage()
        self.ele_add_goods()
        self.ele_frame_out()

    def batch_derive(self):
        self.ele_menu_frame()
        self.ele_goods_manage()
        self.ele_batch_derive()
        self.ele_frame_out()

    def derive_uploading(self):
        self.ele_menu_frame()
        self.ele_goods_manage()
        self.ele_derive_uploading()
        self.ele_frame_out()
